#ifndef TLS_UNIFORM_GRID_H
#define TLS_UNIFORM_GRID_H
#include "linear_aggr.h"

namespace tls{

  struct uniform_grid{
    static const int MAXN=64;

    linear_aggr mesh;
    vector<triangle*> voxels[MAXN][MAXN][MAXN];
    aabb world;
    vec3 unit;

    uniform_grid(const linear_aggr& aggr);
    bool intersect(ray& r,isect& hit)const;
    bool intersectP(ray& r)const;

    int pos2voxel(const vec3& p,int axis)const{
      vec3 extent=p-world.l;
      return (int)(extent[axis] / unit[axis]);
    }
    real voxel2pos(int p,int axis)const{
      return world.l[axis] + unit[axis] * p;
    }

  };//struct uniform_grid

}//namespace tls

#endif
